package com.shxc.smarttrade.old.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.shxc.smarttrade.R;
import com.zzhoujay.richtext.RichText;

import java.io.InputStream;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by jcdev1 on 2017/6/23.
 */

public class UserAgreementActivity extends BaseActivity {

    @BindView(R.id.tv_center)
    TextView tvCenter;
    @BindView(R.id.tv_user_agreement)
    TextView tvUserAgreement;
    @BindView(R.id.tv_one)
    TextView tvOne;
    @BindView(R.id.tv_two)
    TextView tvTwo;
    int tag = -1;
    private RichText richText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_agreement);
        tag = getIntent().getIntExtra("tag", -1);
        initView();
        initData();
    }

    private void initView() {
        if (tag == 1) {
            tvOne.setText("外汇交易大师用户协议》");
            tvOne.setVisibility(View.VISIBLE);
            tvCenter.setText("用户协议");

        } else if (tag == 2) {
            tvOne.setText("《外汇交易大师交易协议》");
            tvOne.setVisibility(View.VISIBLE);
            tvCenter.setText("交易协议");
        } else if (tag == 3) {
            tvCenter.setText("详情");
            tvOne.setVisibility(View.GONE);
        } else if (tag == 4) {
            tvCenter.setText("交易条件和须知");
            tvOne.setVisibility(View.GONE);
        } else if (tag == 5) {
            tvCenter.setText("隐私条款");
            tvOne.setVisibility(View.GONE);
        } else if (tag == 6) {
            tvCenter.setText("投资风险提示");
            tvOne.setVisibility(View.GONE);
            tvTwo.setVisibility(View.VISIBLE);
        } else if (tag == 7) {
            tvCenter.setText("外汇风险披露");
            tvOne.setVisibility(View.GONE);
        } else if (tag == 8) {
            tvCenter.setText("关于我们");
            tvOne.setVisibility(View.GONE);
        }

    }

    private void initData() {
        String kLineData = "";
        try {
            InputStream in = null;
            if (tag == 1)
                in = getResources().getAssets().open("useragreement.txt");
            else if (tag == 2)
                in = getResources().getAssets().open("tradeagreement.txt");
            else if (tag == 3)
                in = getResources().getAssets().open("antforex_intrduce.txt");
            else if (tag == 4)
                in = getResources().getAssets().open("tradercondition.txt");
            else if (tag == 5)
                in = getResources().getAssets().open("privacypolicy.txt");
            else if (tag == 6)
                in = getResources().getAssets().open("riskwaring.txt");
            else if (tag == 7)
                in = getResources().getAssets().open("risk_disclosure.txt");
            else if (tag == 8)
                in = getResources().getAssets().open("aboutus.txt");
            int length = in.available();
            byte[] buffer = new byte[length];
            in.read(buffer);
            kLineData = new String(buffer, "UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (tag == 3 || tag == 4 || tag == 6 || tag == 5)
            richText = RichText.from(kLineData).into(tvUserAgreement);
        else
            tvUserAgreement.setText(kLineData);


    }

    @OnClick(R.id.rl_left)
    public void onViewClicked() {
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (richText != null) {
            richText.clear();
            richText = null;
        }
    }
}
